/*
 * 	Flan.Zeng 2011-2016	http://git.oschina.net/signup?inviter=flan
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.flan.stock.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ScrollView;

/**
 * 自定义外层ScrollView,当ScrollView滚动到底部时交出触摸事件
 * @author flan
 * @date   2015年11月9日
 */
public class OuterScrollView extends ScrollView {
	
	
	private boolean isScrollToBottom = false;
	private OnScrollChangeListener scrollChangeListener;

	public OuterScrollView(Context context) {
		super(context,null);
	}

	public OuterScrollView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}
	
	/**
	 * 暴露原有的受保护的滚动监听方法
	 * @param listener
	 */
	public void setOnScrollChangeListener(OnScrollChangeListener listener){
		this.scrollChangeListener = listener;
	}
	
	/**
	 * 滚动视图的可滚动范围是所有子元素的高度。
	 * 返回值 由垂直方向滚动条代表的所有垂直范围，缺省的范围是当前视图的画图高度
	 */
	public int getComputeVerticalScrollRange(){
		return super.computeHorizontalScrollRange();
	}
	
	public void setScrollToBottom(boolean isScrollToBottom) {
		this.isScrollToBottom = isScrollToBottom;
	}

	/*@Override
	public boolean onInterceptTouchEvent(MotionEvent ev) {
		if(isScrollToBottom){
			return false;
		}
		return true;
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent ev) {
		return super.onTouchEvent(ev);
	}*/
	
	@Override
	protected void onScrollChanged(int x, int y, int oldx, int oldy) {
		super.onScrollChanged(x, y, oldx, oldy);
		if(scrollChangeListener != null){
			scrollChangeListener.OnScrollChange(x, y, oldx, oldy);
		}
	}
	
	public interface OnScrollChangeListener{
		public void OnScrollChange(int x, int y, int oldx, int oldy);
	}
}
